package com.mamahao.vmnetframework.framework.view

import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModel
import android.support.v4.app.Fragment
import com.mamahao.vmnetframework.framework.event.ActionTodo
import com.mamahao.vmnetframework.framework.event.BaseActionEvent
import com.mamahao.vmnetframework.framework.viewmodel.BaseViewModel


fun Fragment.initViewModel(viewModel: ViewModel, block: ((BaseActionEvent?) -> Boolean)? = null) : ViewModel{
    return viewModel.apply {
        if(this is BaseViewModel){
            mActionLiveData.observe(this@initViewModel, Observer<BaseActionEvent> {
                baseActionEvent: BaseActionEvent? ->
                ActionTodo.actionMessageTodo(activity, baseActionEvent, block)
            })
        }
    }
}